#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <string>
#include <vector>

using ll = int64_t;
const ll mod = 998244353;

#define p(v)do{\
    std::cout<<#v<<":\n";\
    for(ll i=1;i<=n;i++){\
        for(ll j=1;j<=m;j++){\
            std::cout<<(v)[i][j]<<' ';\
        }\
        std::cout<<"\n";\
    }\
}while(0)

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t,id;
    std::cin>>t>>id;
    while(t--){
        ll n,m,c,f;
        std::cin>>n>>m>>c>>f;
        static std::vector<std::vector<bool>> map;
        map.clear();
        map.resize(n+1,std::vector<bool>(m+1));
        for(ll i=1;i<=n;i++){
            static std::string s;
            std::cin>>s;
            ll idx=1;
            for(char c:s){
                map[i][idx++]=c-'0';
            }
        }
        
        static std::vector<std::vector<ll>> rt;
        rt.clear();
        rt.resize(n+1,std::vector<ll>(m+2));
        for(ll i=1;i<=n;i++){
            for(ll j=m;j>=1;j--){
                if(map[i][j]==0){
                    rt[i][j]=(rt[i][j+1]+1)%mod;
                }
            }
        }
        // p(rt);
        static std::vector<std::vector<ll>> d;
        d.clear();
        d.resize(n+2,std::vector<ll>(m+1));
        for(ll j=1;j<=m;j++){
            for(ll i=n;i>=1;i--){
                if(map[i][j]==0){
                    d[i][j]=(d[i+1][j]+1)%mod;
                }
            }
        }
        // p(d);
        ll ansc=0,ansf=0;
        static std::vector<std::vector<ll>> visc,visf;
        visc.clear();visc.resize(n+1,std::vector<ll>(m+1));
        visf.clear();visf.resize(n+1,std::vector<ll>(m+1));
        for(ll i=1;i<=n-2;i++){
            for(ll j=1;j<=m;j++){
                if(rt[i][j]<=1 || rt[i+1][j]==0 || rt[i+2][j]==0){
                    continue;
                }
                ll top = rt[i][j]-1;
                // ll nansc = 0;
                // ll nansf = 0;
                ll bc=ansc,bf=ansf;
                for(ll k=i+2;k<=n;k++){
                    if(rt[k][j]==0)break;
                    if(rt[k][j]>1){
                        // if(visc[i][j]){
                        //     ansc=(ansc+visc[i][j])%mod;
                        // }else{
                            ansc=(ansc+top*(rt[k][j]-1)%mod)%mod;
                            visc[i][j]=((ansc-bc)%mod+mod)%mod;
                        // }
                        // if(visf[i][j]){
                        //     ansf=(ansf+visf[i][j])%mod;
                        // }else{
                            ansf=(ansf+top*(rt[k][j]-1)%mod*(d[k][j]-1)%mod)%mod;
                            visf[i][j]=((ansf-bf)%mod+mod)%mod;
                        // }
                        // printf("C format i=%lld, j=%lld, k=%lld, nowc=%lld\n"
                        //     ,i,j,k, ansc+=top*(rt[k][j]-1));
                        // printf("F format i=%lld, j=%lld, k=%lld, nowf=%lld\n"
                        //     ,i,j,k, ansf+= top*(rt[k][j]-1)*(d[k][j]-1));
                    }
                }
            }
        }
        std::cout<<ansc*c%mod<<" "<<ansf*f%mod<<"\n";
    }
}